<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path;
%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=0">
<title>云校通-教师-教师请假详情</title>
<jsp:include page="/WEB-INF/page/common/_header.jsp"></jsp:include>
<body ontouchstart>
	<div class="weui_tab tab-bottom">
		<div class="weui-header bg-blue"> 
	  		<div class="weui-header-left"><a href="<%=basePath %>/ls/teacher/leave" class="icon icon-109 f-white">返回</a></div>
	    	<h1 class="weui-header-title">教师请假详情</h1>
	    </div>
	    <div class="weui_tab_bd">
	    	<div class="weui_cells mt0">
                <div class="weui_media_box weui_media_appmsg">
                    <div class="weui_media_hd">
                        <img style="border-radius: 100%;" class="weui_media_appmsg_thumb" src="${config.imgUrl }${detail.headImgUrl}" alt="">
                    </div>
                    <div class="weui_media_bd">
                        <h4 class="weui_media_title">${detail.teacherName }</h4>
                        <p class="weui_media_desc">
                        	<c:choose>
                        		<c:when test="${detail.leaveStatus == '000' }">
                        			<c:choose>
                        				<c:when test="${not empty detail.backStatus && detail.backStatus != '003' }">
                        					<c:choose>
				                        		<c:when test="${detail.backStatus == '001' }">
				                        			<span class="f-yellow2">销假：等待${detail.approver }审批</span>
				                        		</c:when>
				                        		<c:when test="${detail.backStatus == '002' }">
				                        			<span class="f-red2">销假：${detail.approver }已驳回</span>
				                        		</c:when>
				                        		<c:when test="${detail.backStatus == '000' }">
				                        			<span class="f-green2">${detail.approver }审批通过</span>
				                        		</c:when>
				                        	</c:choose>
                        				</c:when>
                        				<c:otherwise>
                        					<span class="f-green2">${detail.approver }审批通过</span>
                        				</c:otherwise>
                        			</c:choose>
                        		</c:when>
                        		<c:when test="${detail.leaveStatus == '001' }">
                        			<span class="f-yellow2">等待${detail.approver }审批</span>
                        		</c:when>
                        		<c:when test="${detail.leaveStatus == '002' }">
                        			<span class="f-red2">${detail.approver }已驳回</span>
                        		</c:when>
                        		<c:when test="${detail.leaveStatus == '003' }">
                        			<span class="f-red2">已撤销</span>
                        		</c:when>
                        	</c:choose>
                        </p>
                    </div>
                </div>
			</div>
		    <div class="weui_cells mt0">
			    <div class="weui_cell">
			    	<div class="weui_cell_bd weui_cell_primary">
						<span class="f-graybc">请假教师：</span>${detail.teacherName }
					</div>
			    </div>
			    <div class="weui_cell">
			    	<div class="weui_cell_bd weui_cell_primary">
						<span class="f-graybc">请假类型：</span>${detail.leaveType }
					</div>
			    </div>
			    <div class="weui_cell">
					<div class="weui_cell_bd weui_cell_primary">
						<span class="f-graybc">是否需要调代课：</span>${detail.isLesson == 1 ? '是' : '否'}
					</div>
				</div>
				<div class="weui_cell">
					<div class="weui_cell_bd weui_cell_primary">
						<span class="f-graybc">请假时间：</span>${detail.startTime } 到 ${detail.endTime }
					</div>
				</div>
				<div class="weui_cell">
					<div class="weui_cell_bd weui_cell_primary">
						<span class="f-graybc">请假天数：</span>${detail.leaveDays }天
					</div>
				</div>
				<div class="weui_cell">
					<div class="weui_cell_bd weui_cell_primary">
						<span class="f-graybc">请假原因：</span>${detail.leaveReason }
					</div>
				</div>
				<c:if test="${!empty attachList }">
					<div class="weui_cells_title">附件：</div>
				    <div class="weui-flex p10">
						<div class="mailbox img-click">
							<c:forEach var="itm" items="${attachList }">
                   					<img onclick="imgClick(this)" src="${config.imgUrl }${itm.attachmentUrl }">
                   			</c:forEach>
						</div>
					</div>
			    </c:if>
			</div>
			<c:if test="${not empty detail.backStatus && detail.backStatus != '003'}">
				<div class="weui_cells mt0">
					<div class="weui_cells_title">销假信息</div>
					<div class="weui_cell">
						<div class="weui_cell_bd weui_cell_primary">
							<span class="f-graybc">销假时间：</span>${detail.backStartDate } 到 ${detail.backEndDate }
						</div>
					</div>
					<div class="weui_cell">
						<div class="weui_cell_bd weui_cell_primary">
							<span class="f-graybc">销假天数：</span>${detail.backDays }天
						</div>
					</div>
					<c:if test="${detail.backStatus == '001' }">
						<div class="weui_cell">
							<div class="weui_cell_bd weui_cell_primary">
								<span class="f-graybc">实际请假天数：</span>${detail.leaveDays - detail.backDays }天
							</div>
						</div>
					</c:if>
					<c:if test="${detail.backStatus == '002' }">
						<div class="weui_cell">
							<div class="weui_cell_bd weui_cell_primary">
								<span class="f-graybc">驳回原因：</span>${detail.rejectReason }
							</div>
						</div>
					</c:if>
					<div class="weui_cell">
				    	<div class="weui_cell_bd weui_cell_primary">
							<span class="f-graybc">销假状态：</span><c:choose>
				                        		<c:when test="${detail.backStatus == '001' }">
				                        			<span class="f-yellow2">销假：等待${detail.approver }审批</span>
				                        		</c:when>
				                        		<c:when test="${detail.backStatus == '002' }">
				                        			<span class="f-red2">销假：${detail.approver }已驳回</span>
				                        		</c:when>
				                        		<c:when test="${detail.backStatus == '000' }">
				                        			<span class="f-green2">${detail.approver }审批通过</span>
				                        		</c:when>
				                        	</c:choose>
						</div>
				    </div>
				</div>
			</c:if>
			<div class="weui_cells mt10">
	        	<div class="weui_cells_title">请假期间工作安排</div>
				<div class="weui_cell bd-t0" style="padding:0;"> 	        	
					<table class="weui-table weui-border-tb">
	                	<thead>
			                <tr>
				                <th width="28%">学科</th>
				                <th width="20%">正课<br/>节数</th>
				                <th width="16%">自习<br/>节数</th>
				                <th width="16%">选修课<br/>节数</th>
				                <th width="20%">值日<br/>天数</th>
			                </tr>
		                </thead>
		                <tbody>
		                	<tr>
		                		<td>请假期间工作量</td>
		                		<td>${detail.time1Lesson1 }</td>
		                		<td>${detail.time1Lesson2 }</td>
		                		<td>${detail.time1Lesson3 }</td>
		                		<td>${detail.time1Lesson4 }</td>
		                	</tr>
		                	<tr>
		                		<td>假前假后自己上课节（天）数</td>
		                		<td>${detail.time2Lesson1 }</td>
		                		<td>${detail.time2Lesson2 }</td>
		                		<td>${detail.time2Lesson3 }</td>
		                		<td>${detail.time2Lesson4 }</td>
		                	</tr>
		                	<tr>
		                		<td>替班人及替班节（天）数</td>
		                		<td>${detail.time3Lesson1 }</td>
		                		<td>${detail.time3Lesson2 }</td>
		                		<td>${detail.time3Lesson3 }</td>
		                		<td>${detail.time3Lesson4 }</td>
		                	</tr>
		                	<tr>
		                		<td>是否值日</td>
		                		<td>${detail.isDuty }</td>
		                		<td colspan="2">值日替班人</td>
		                		<td>${detail.dutyReplacer }</td>
		                	</tr>
		                	<tr>
		                		<td>是否晚修</td>
		                		<td>${detail.isLate }</td>
		                		<td colspan="2">晚修替班人</td>
		                		<td>${detail.lateReplacer }</td>
		                	</tr>
		                	<tr>
		                		<td>职&nbsp;&nbsp;&nbsp;&nbsp;务</td>
		                		<td>${detail.position }</td>
		                		<td colspan="2">职务委托人</td>
		                		<td>${detail.positionConsigner }</td>
		                	</tr>
		                </tbody>
	            	</table>
	            </div>
	        </div>
			<div class="weui_cells mt10">
		    	<div class="weui_cells_title">审批详情</div>
		    	<div class="weui_cell">
					<div class="weui_cell_bd weui_cell_primary">
						<span class="f-graybc">审批人：</span>${detail.approver }
					</div>
				</div>
		    	<div class="weui_cell">
					<div class="weui_cell_bd weui_cell_primary">
						<span class="f-graybc">审批状态：
						<c:choose>
							<c:when test="${detail.leaveStatus == '000'}">
								<c:choose>
                      				<c:when test="${not empty detail.backStatus && detail.backStatus != '003'}">
                      					<c:choose>
			                        		<c:when test="${detail.backStatus == '001' }">
			                        			<span class="f-yellow2">销假：等待${detail.approver }审批</span>
			                        		</c:when>
			                        		<c:when test="${detail.backStatus == '002' }">
			                        			<span class="f-red2">销假：${detail.approver }已驳回</span>
			                        		</c:when>
			                        		<c:when test="${detail.backStatus == '000' }">
			                        			<span class="f-green2">${detail.approver }审批通过</span>
			                        		</c:when>
			                        	</c:choose>
                      				</c:when>
                      				<c:otherwise>
                      					<span class="f-green2">${detail.approver }审批通过</span>
                      				</c:otherwise>
                      			</c:choose>
							</c:when>
							<c:when test="${detail.leaveStatus == '001'}"><span class="f-orange">待审批</span></c:when>
							<c:when test="${detail.leaveStatus == '002'}">已驳回</c:when>
							<c:when test="${detail.leaveStatus == '003'}">已撤消</c:when>
						</c:choose></span>
					</div>
				</div>
				<c:if test="${detail.leaveStatus == '002' }">
					<div class="weui_cell">
						<div class="weui_cell_bd weui_cell_primary">
							<span class="f-graybc">驳回原因：${detail.rejectReason }</span>
						</div>
					</div>
				</c:if>
				<c:if test="${!empty detail.message }">
					<div class="weui_cell">
						<div class="weui_cell_bd weui_cell_primary">
							<span class="f-graybc">审批留言：</span>${detail.message }
						</div>
					</div>
				</c:if>
		    </div>
			<c:choose>
				<c:when test="${detail.approverId == user.teacher.id && (detail.leaveStatus == '001' || detail.backStatus == '001')}">
					<div class="weui_cells mb40"></div>
					<section class="weui-menu">
				        <div class="weui-menu-inner" onclick="approvalSubmit(${detail.id},1)">
				            <span>驳回</span>
				        </div>
				        <div class="weui-menu-inner" onclick="approvalSubmit(${detail.id},2)">
				            <span>同意</span>
				        </div>
				    </section>
				    <div style="display:none;" id="weui_mask" class="weui_mask weui_mask_visible" style="transform-origin: 0px 0px 0px; opacity: 1; transform: scale(1, 1);"></div>
					 <div style="display:none;" id="weui_dialog" class="weui_dialog weui_dialog_visible" style="transform-origin: 0px 0px 0px; opacity: 1; transform: scale(1, 1);">
						<div class="weui_dialog_hd">
							<strong class="weui_dialog_title">请输入内容</strong>
						</div>
						<div class="weui_dialog_bd">
							<textarea class="weui_input weui-prompt-input" style="height: 80px;width: 95%;" rows="10" id="rejectText"></textarea>
						</div>
						<div class="weui_dialog_ft">
							<a href="javascript:;" id="rejectCancel" class="weui_btn_dialog default">取消</a>
							<a href="javascript:;" id="rejectSure" class="weui_btn_dialog primary">确定</a>
						</div>
					 </div>
				</c:when>
				<c:when test="${detail.teacherId == user.teacher.id && detail.leaveStatus == '001'}">
				    <div class="weui_cells mb40"></div>
				    <section class="weui-menu">
				        <div class="weui-menu-inner" onclick="editorHref(${detail.id})">
				            <span>修改</span>
				        </div>
				        <div class="weui-menu-inner" onclick="cancelApproval(${detail.id},1)">
				            <span>撤消请假</span>
				        </div>
				    </section>
				</c:when>
				<c:when test="${detail.teacherId == user.teacher.id && detail.backStatus == '001'}">
				    <div class="weui_cells mb40"></div>
				    <section class="weui-menu">
				        <div class="weui-menu-inner" onclick="editorHref(${detail.id})">
				            <span>修改</span>
				        </div>
				        <div class="weui-menu-inner" onclick="cancelApproval(${detail.id},2)">
				            <span>撤消销假</span>
				        </div>
				    </section>
				</c:when>
				<c:when test="${empty detail.backStatus && detail.leaveStatus == '000' }">
					<div class="weui_cells mb40"></div>
				    <section class="weui-menu">
				        <div class="weui-menu-inner" onclick="editorHref(${detail.id})">
				            <span>销假申请</span>
				        </div>
				    </section>
				</c:when>
			</c:choose>
		</div>	
	</div>
<script type="text/javascript">
	function editorHref(id){
		window.location.href = basePath + "/ls/teacher/leave/editor/"+id;
	}
	function cancelApproval(id,type) {
        $.confirm("确认取消"+(type==1?"请假":"销假")+"申请", "确认取消？", function(text) {
        	$.ajax({
    	      	url : basePath + "/ls/teacher/leave/cancel",
    		 	type : "post",
    		 	dataType : "json",
    		 	data : {
    		 		applyId: id
    		 	},
    	        success: function(data){
    	        	issubmit = false;
    	        	if(data.code == '000') {
    	        		$("#weui_mask").hide();
    					$("#weui_dialog").hide();
    	        		$.toast("审批成功");
    	        		setTimeout(function() {
    	        			window.location.href = basePath + "/ls/teacher/leave?v=" + new Date().getTime();
    	        		}, 1000);
    	        		return;
    	        	}
    	        	$.toptips("提交失败，请联系管理员");
    	        },
    	        error: function(xhr, type){
    	          
    	        }
    	     });
        }, function() {
          //取消操作
        });
	}
	function approvalSubmit(id,type) {
		var id = id;
		var type = type;
		$("#rejectText").attr("placeholder", type == 1 ? "请输入不同意理由" : "请输入审批留言(可不填)");
		$(".weui_mask").addClass("weui_mask_visible").show();
		$(".weui_dialog").addClass("weui_dialog_visible").show();
		$("#rejectCancel").click(function(){
			$("#rejectText").val(null);
			$("#weui_mask").hide();
			$("#weui_dialog").hide();
		});
		$("#rejectSure").click(function(){
			var params = {id: id};
			var text = $("#rejectText").val();
			if(type == 1) {
				if(text.trim().length == 0) return;
				params.rejectReason = text;
	      		params.leaveStatus = '002';
			}else {
				if(text.trim().length > 0) params.message = text;
				params.leaveStatus = '000';
			}
			auditSubmit(params);
		});
	}
	var issubmit = false;
	function auditSubmit(params) {
		if(issubmit) return;
		issubmit = true;
		$.ajax({
	      	url : basePath + "/ls/teacher/leave/audit",
		 		type : "post",
		 		dataType : "json",
		 		data : params,
	        success: function(data){
	        	issubmit = false;
	        	if(data.code == '000') {
	        		$("#weui_mask").hide();
					$("#weui_dialog").hide();
	        		$.toast("审批成功");
	        		setTimeout(function() {
	        			window.location.href = basePath + "/ls/teacher/leave?v=" + new Date().getTime();
	        		}, 1000);
	        		return;
	        	}
	        	$.toptips("提交失败，请联系管理员");
	        },
	        error: function(xhr, type){
	          
	        }
	     });
	}
</script>
</body>
</html>